unset( $currentValue ); // free RAM in case the value is large
$this->clearLastError();
- if ( $value === false ) {
+ if ( $value === false || $exptime < 0 ) {
$success = true; // do nothing
- } elseif ( $hadNoCurrentValue ) {
+ } elseif ( $valueMatchesOldValue && $attemptsLeft !== $attempts ) {
+ $success = true; // recently set by another thread to the same value
+ } elseif ( $keyWasNonexistant ) {
// Try to create the key, failing if it gets created in the meantime
$success = $this->add( $key, $value, $exptime, $flags );
} else {